package co.chuangdian.oflauncher.folders.setting;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import cn.onekit.CALLBACK;
import cn.onekit.android.ACTIVITY;
import co.chuangdian.oflauncher.OFActivity;
import co.chuangdian.oflauncher.R;
import uc.WizardBar;

public class AddFolderActivity extends OFActivity {
	WizardBar nav;
	Fragment[] steps;

	@Override
	protected void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		this.setContentView(R.layout.foldersetting_add);
		nav = (WizardBar) findViewById(R.id.nav);
		nav.setData(new String[] { "名称", "应用", "封面", "视图" }, new CALLBACK<Integer>() {

			@Override
			public void run(boolean isError, Integer result) {
				goNext(result);
			}

		});
		AddFolder_Step1 AddFolder_Step1 = new AddFolder_Step1();
		AddFolder_Step2 AddFolder_Step2 = new AddFolder_Step2();
		AddFolder_Step3 AddFolder_Step3 = new AddFolder_Step3();
		AddFolder_Step4 AddFolder_Step4 = new AddFolder_Step4();
		AddFolder_Step1.setData(new CALLBACK<String>() {

			@Override
			public void run(boolean isError, String result) {
				goNext(++stepIndex);
			}

		});
		steps = new Fragment[] { AddFolder_Step1, AddFolder_Step2, AddFolder_Step3, AddFolder_Step4 };
		//
		ImageButton nextButton = (ImageButton) findViewById(R.id.nextButton);
		nextButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				goNext(++stepIndex);
			}
		});
		//
		 doneButton = (ImageButton) findViewById(R.id.doneButton);
		 doneButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
			
			}
		});
		//
		goNext(0);
	}
	ImageButton doneButton ;
	int stepIndex = 0;

	void goNext(int stepIndex) {
		this.stepIndex = stepIndex;
		doneButton.setVisibility(stepIndex==steps.length-1?View.VISIBLE:View.GONE);
		//
		FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
		ft.replace(R.id.fragment, steps[stepIndex]);
		ft.commit();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		switch (keyCode) {
		case KeyEvent.KEYCODE_BACK:
			if (stepIndex > 0) {
				goNext(--stepIndex);
				return false;
			}
		default:
			break;
		}
		return super.onKeyDown(keyCode, event);
	}
}
